/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.elec.plan.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.elec.plan.entity.ElecPlan;
import cn.net.ecode.elec.plan.service.ElecPlanService;

/**
 * 报电量Controller
 * @author AlanShelby
 * @version 2019-08-28
 */
@Controller
@RequestMapping(value = "${adminPath}/plan/elecPlan")
public class ElecPlanController extends BaseController {

	@Autowired
	private ElecPlanService elecPlanService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElecPlan get(String id, boolean isNewRecord) {
		return elecPlanService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("plan:elecPlan:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElecPlan elecPlan, Model model) {
		model.addAttribute("elecPlan", elecPlan);
		return "elec/plan/elecPlanList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("plan:elecPlan:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<ElecPlan> listData(ElecPlan elecPlan, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ElecPlan> page = elecPlanService.findPage(new Page<ElecPlan>(request, response), elecPlan); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("plan:elecPlan:view")
	@RequestMapping(value = "form")
	public String form(ElecPlan elecPlan, Model model) {
		model.addAttribute("elecPlan", elecPlan);
		return "elec/plan/elecPlanForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("plan:elecPlan:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(ElecPlan elecPlan) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, elecPlan)){
			return renderResult(Global.FALSE, message);
		}
		elecPlanService.save(elecPlan);
		return renderResult(Global.TRUE, "保存报电量成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("plan:elecPlan:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(ElecPlan elecPlan) {
		elecPlanService.delete(elecPlan);
		return renderResult(Global.TRUE, "删除报电量成功！");
	}

}